<template>
  <div class="app-container ">
    <el-form
      ref="form"
      label-position="top"
      size="mini"
      :model="form"
      :rules="rules"
      :inline="true"
      label-width="180px"
    >
      <el-tabs v-model="activeName">
        <el-tab-pane style="padding-top:10px" :label="'送'+lang.points+'设置'" :name="'送'+lang.points+'设置'">
          <el-divider content-position="left">积分兑换设置</el-divider>
          <el-row>
            <el-col :span="24">
              <el-form-item :label="'开启'+lang.points+'兑钱设置'" prop="status" style="width:150px;">
                <el-switch
                  v-model="form.points_open"
                  active-value="1"
                  inactive-value="0"
                  active-text="开启"
                  inactive-text="关闭"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-divider />

          <el-row>
            <el-col>
              <el-form-item :label="'开启统一送'+lang.points+'设置'" prop="status">
                <el-switch
                  v-model="form.status"
                  active-value="1"
                  inactive-value="0"
                  active-text="开启"
                  inactive-text="关闭"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="邀请新用户">
                <el-input-number
                  v-model="form.addmember"
                  controls-position="right"
                  style="width:300px;"
                  auto-complete="off"
                  clearable
                  :min="0"
                  placeholder="邀请新用户加多少分"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="邀请分销达人">
                <el-input-number
                  v-model="form.addagent"
                  controls-position="right"
                  style="width:300px;"
                  auto-complete="off"
                  clearable
                  :min="0"
                  placeholder="邀请分销达人加多少分"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item :label="'邀请'+lang.technical+'入驻'">
                <el-input-number
                  v-model="form.addtechnical"
                  controls-position="right"
                  style="width:300px;"
                  auto-complete="off"
                  clearable
                  :min="0"
                  :placeholder="'邀请'+lang.technical+'入驻加多少分'"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="邀请商户入驻">
                <el-input-number
                  v-model="form.addstore"
                  controls-position="right"
                  style="width:300px;"
                  auto-complete="off"
                  clearable
                  :min="0"
                  placeholder="邀请商户入驻加多少分"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="直接付款赠送积分比例">
                <el-input v-model="form.paybill" style="width:200px;" auto-complete="off" clearable placeholder="直接付款赠送积分比例">
                  <template slot="append"><span>%</span></template>
                </el-input>
                <div class="help-block">直接付款/商家收款码收款，积分按金额比例赠送</div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item :label="lang.points+'分期到帐'" prop="is_staging">
                <el-switch v-model="form.is_staging" active-value="1" inactive-value="0" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="form.is_staging==1">
            <el-col :span="24">
              <el-form-item label="每期到帐比例">
                <el-input v-model="form.stagingpoints" style="width:300px;" auto-complete="off" clearable placeholder="每期到帐比例">
                  <template slot="append"><span>%</span></template>
                </el-input>
                <div class="help-block">每期到帐比例</div>
              </el-form-item>
            </el-col>
          </el-row>
          <div v-if="form.is_staging==1">
            <el-row>
              <el-col :span="24">
                <el-form-item label="分期到帐周期">
                  <el-radio-group v-model="form.stagingweek">
                    <el-radio label="1">周一</el-radio>
                    <el-radio label="2">周二</el-radio>
                    <el-radio label="3">周三</el-radio>
                    <el-radio label="4">周四</el-radio>
                    <el-radio label="5">周五</el-radio>
                    <el-radio label="6">周六</el-radio>
                    <el-radio label="7">周日</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="开启分期递增" prop="is_staging">
                  <el-switch v-model="form.is_increment" active-value="1" inactive-value="0" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row v-if="form.is_increment==1">
              <el-col :span="24">
                <el-form-item label="分期递增比例">
                  <el-input v-model="form.increment" style="width:300px;" auto-complete="off" clearable placeholder="请输入">
                    <template slot="append"><span>%</span></template>
                  </el-input>
                  <div class="help-block">比上一期递增</div>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
          <el-row>
            <el-col :span="24">
              <el-form-item label="关闭在线支付送积分">
                <el-radio-group v-model="form.is_close_online_pay">
                  <el-radio label="1">关闭</el-radio>
                  <el-radio label="0">开启</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="关闭线下支付送积分">
                <el-radio-group v-model="form.is_close_offline_pay">
                  <el-radio label="1">关闭</el-radio>
                  <el-radio label="0">开启</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="关闭使用优惠卷送积分">
                <el-radio-group v-model="form.is_close_coupon">
                  <el-radio label="1">关闭</el-radio>
                  <el-radio label="0">开启</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
      <el-form-item>
        <el-button size="mini" type="primary" @click="submit">保存设置</el-button>
      </el-form-item>
    </el-form>

  </div>
</template>
<script>
export default {
  name: 'Configpoints',
  components: {
  },
  data() {
    return {
      lang: {},

      loading: false,
      activeName: '',
      rules: {},
      stagingweekAll: [
        { key: 1, value: '周一' },
        { key: 2, value: '周二' },
        { key: 3, value: '周三' },
        { key: 4, value: '周四' },
        { key: 5, value: '周五' },
        { key: 6, value: '周六' },
        { key: 7, value: '周日' }
      ],
      form: {
        addcustomer: '',
        adddongtai: '',
        upjieduan: '',
        deal: '',
        status: 0
      }
    }
  },
  mounted() {
    this.$api.post('/Lang/getlang').then(res => {
      this.lang = res.data
      this.activeName = '送' + this.lang.points + '设置'
    })
    this.$api.post('/config/getInfo', { mo: 'points' }).then(res => {
      this.form = JSON.stringify(res.data) == '[]' ? {} : res.data
      this.setDefaultVal('keyword')
    })
  },
  methods: {
    submit() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.loading = true
          this.$api.post('/config/update', this.form).then(res => {
            this.$message({ message: '操作成功', type: 'success' })
          }).catch(() => {
            this.loading = false
          })
        }
      })
    },
    setDefaultVal(key) {
      if (this.form[key] == null || this.form[key] == '') {
        this.form[key] = []
      }
    }
  }
}
</script>
